Skip to content

refactor(core): introduce CommandContext for the queue+freeze prelude#1441

Merged
mergify[bot] merged 3 commits into
mainfrom
devs/jd/worktree-rust-port/introduce-commandcontext-queue-freeze-prelude--1b272570
May 27, 2026
Merged

refactor(core): introduce CommandContext for the queue+freeze prelude#1441
mergify[bot] merged 3 commits into
mainfrom
devs/jd/worktree-rust-port/introduce-commandcontext-queue-freeze-prelude--1b272570

Conversation

@jd
Copy link
Copy Markdown
Member

@jd jd commented May 19, 2026

Every queue and freeze command opens with the same four-line
ritual: resolve repository slug, resolve token, resolve API URL,
build a Mergify-flavored HTTP client. Wrap those into a
CommandContext::resolve(...) constructor + ctx.mergify_client()
builder living in a new mergify_core::command_context module.

The eight queue/freeze command preludes shrink from

let repository = auth::resolve_repository(opts.repository)?;
let token = auth::resolve_token(opts.token)?;
let api_url = auth::resolve_api_url(opts.api_url)?;
let client = HttpClient::new(api_url, token, ApiFlavor::Mergify)?;

to

let ctx = CommandContext::resolve(opts.repository, opts.token, opts.api_url)?;
let client = ctx.mergify_client()?;

auth::resolve_* stay public for the specialized callers that
don't fit the shape: config validate needs no repository,
config simulate derives the repo from a PR URL, ci scopes-send
resolves the repo from CI-env vars (different fallback chain).
Those keep wiring up the lower-level helpers by hand.

Net -73 / +63 across 9 files; conceptually the bigger win is
that "the prelude of a Mergify command" is now a named concept
with one fix-it-once point.

Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com

Depends-On: #1439

@jd
Copy link
Copy Markdown
Member Author

jd commented May 19, 2026

This pull request is part of a Mergify stack:

# Pull Request Link
1 fix(cli): accept --debug on the Rust binary and actually toggle it in Python #1464
2 refactor(rust): share test scaffolding via mergify-test-support crate #1439
3 refactor(core): introduce CommandContext for the queue+freeze prelude #1441 👈
4 refactor(ci): consolidate the CI-env scrubber into a shared testing module #1442
5 refactor: drop stale Phase X.Y doc markers and one inline color branch #1443
6 refactor(tui): share StyledGlyph across queue show/status renderers #1444
7 refactor(queue): drop indexmap, group_by_scope returns a Vec<(K, V)> #1445
8 refactor(ci): swap uuid for getrandom in the GHA heredoc delimiter #1446
9 refactor(config): standardize the workspace on serde_yaml_ng for YAML parsing #1447
10 test(ci): add live smoke test for ci scopes select-all path #1460
11 feat(rust): port ci scopes to native Rust #1461
12 feat(ci): parse JUnit XML reports in native Rust #1465
13 feat(ci): encode JUnit cases as OTLP and upload to Mergify CI Insights #1466
14 feat(ci): promote ci junit-process from shim to native Rust #1467
15 feat(ci): promote ci junit-upload from shim to native as a deprecated alias #1468
16 fix(ci): prefer GitHub Actions PR-event head SHA over GITHUB_SHA #1469

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 19, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 ⛓️ Depends-On Requirements

Wonderful, this rule succeeded.

Requirement based on the presence of Depends-On in the body of the pull request

🟢 🤖 Continuous Integration

Wonderful, this rule succeeded.
  • all of:
    • check-success=ci-gate

🟢 👀 Review Requirements

Wonderful, this rule succeeded.
  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert|ui)(?:\(.+\))?:

🟢 🔎 Reviews

Wonderful, this rule succeeded.
  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

Wonderful, this rule succeeded.
  • body ~= (?ms:.{48,})

@jd jd force-pushed the devs/jd/worktree-rust-port/share-test-scaffolding-via-mergify-test-support--f9d688cd branch from 32628b4 to d7feae3 Compare May 19, 2026 13:04
@jd jd force-pushed the devs/jd/worktree-rust-port/introduce-commandcontext-queue-freeze-prelude--1b272570 branch from 32cbcd9 to c542b1f Compare May 19, 2026 13:04
@jd jd temporarily deployed to func-tests-live May 19, 2026 13:04 — with GitHub Actions Inactive
@jd jd temporarily deployed to func-tests-live May 19, 2026 13:04 — with GitHub Actions Inactive
@jd
Copy link
Copy Markdown
Member Author

jd commented May 19, 2026

Revision history

# Type Changes Reason Date
1 initial 32cbcd9 2026-05-19 13:04 UTC
2 rebase 32cbcd9 → c542b1f (rebase only) 2026-05-19 13:04 UTC
3 rebase c542b1f → 141fec6 (rebase only) 2026-05-19 14:15 UTC
4 rebase 141fec6 → f0427d0 (rebase only) 2026-05-20 08:42 UTC
5 rebase f0427d0 → 075f94d (rebase only) 2026-05-20 09:05 UTC
6 rebase 075f94d → 680749b (rebase only) 2026-05-21 07:25 UTC
7 rebase 680749b → e97a0dc (rebase only) 2026-05-21 07:56 UTC
8 rebase e97a0dc → 0774750 (rebase only) 2026-05-21 12:39 UTC
9 rebase 0774750 → 74235d6 (rebase only) 2026-05-22 07:10 UTC
10 rebase 74235d6 → beee2a7 (rebase only) 2026-05-22 14:40 UTC
11 rebase beee2a7 → d599400 (rebase only) 2026-05-27 07:53 UTC
12 rebase d599400 → 5143191 (rebase only) 2026-05-27 08:27 UTC

@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 19, 2026 13:04 Failure
@mergify mergify Bot requested a review from a team May 19, 2026 13:19
@jd jd force-pushed the devs/jd/worktree-rust-port/share-test-scaffolding-via-mergify-test-support--f9d688cd branch from d7feae3 to bdea5bb Compare May 19, 2026 14:14
@jd jd force-pushed the devs/jd/worktree-rust-port/introduce-commandcontext-queue-freeze-prelude--1b272570 branch from c542b1f to 141fec6 Compare May 19, 2026 14:14
@jd jd temporarily deployed to func-tests-live May 19, 2026 14:15 — with GitHub Actions Inactive
@jd jd temporarily deployed to func-tests-live May 19, 2026 14:15 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 19, 2026 14:15 Failure
@jd jd marked this pull request as ready for review May 19, 2026 14:56
jd and others added 3 commits May 27, 2026 10:20
… Python

Two coupled gaps the same user-visible bug was hiding:

1. The Rust binary never declared the top-level `--debug` flag the
   Python CLI accepts. Invocations like `mergify --debug ci git-refs`
   were rejected with `error: unexpected argument '--debug' found`
   the moment a command was promoted from shim to native. Add
   `debug: bool` as a `global = true` argument on `CliRoot`; native
   commands accept it as a no-op (no native code path consults the
   flag yet) and shimmed dispatches re-inject `--debug` at the front
   of the forwarded argv so the Python `cli` group still receives it.

2. The Python `cli.py` parsed `--debug` into `ctx.obj["debug"]` but
   never called `utils.set_debug(...)`, so the module-level `_DEBUG`
   toggle stayed `False` and the 6+ `if is_debug():` sites in
   `utils.py` / `stack/*` never fired regardless of the flag. Wire
   `set_debug(debug=debug)` from the root group so the flag has the
   effect users have always expected it to have.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Change-Id: I62ac941db12c55c988896086d7042c3dacf863af
Every command crate's test module re-rolled the same ~30 LOC of
`SharedBytes` / `SharedWriter` / `Captured` / `make_output` glue —
about 350 LOC of pure boilerplate across 15 files, drifting over
time (some `Captured` had `stderr`, some didn't; one file even
carried a `_stderr_accessor_lives` dead-code stub just to silence
the resulting warning).

Extract the canonical version into a new `mergify-test-support`
crate that other crates pull in as a `dev-dependencies`. The new
`Captured` API exposes `human()` / `new(mode)` constructors and
`stdout()` / `stderr()` accessors, so the common pattern shrinks
from a 12-line `String::from_utf8(cap.stdout.lock().unwrap().clone())`
to `let s = cap.stdout()`.

Net `-418 / +114` lines across the workspace. Behavior unchanged;
all 233 tests pass.

The crate is `publish = false` and only ever appears under
`[dev-dependencies]`, so the test-only types never leak into a
production build.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Change-Id: If9d688cdaf55360ba90f386d2020b52346c19b28
Every `queue` and `freeze` command opens with the same four-line
ritual: resolve repository slug, resolve token, resolve API URL,
build a Mergify-flavored HTTP client. Wrap those into a
`CommandContext::resolve(...)` constructor + `ctx.mergify_client()`
builder living in a new `mergify_core::command_context` module.

The eight queue/freeze command preludes shrink from

    let repository = auth::resolve_repository(opts.repository)?;
    let token = auth::resolve_token(opts.token)?;
    let api_url = auth::resolve_api_url(opts.api_url)?;
    let client = HttpClient::new(api_url, token, ApiFlavor::Mergify)?;

to

    let ctx = CommandContext::resolve(opts.repository, opts.token, opts.api_url)?;
    let client = ctx.mergify_client()?;

`auth::resolve_*` stay public for the specialized callers that
don't fit the shape: `config validate` needs no repository,
`config simulate` derives the repo from a PR URL, `ci scopes-send`
resolves the repo from CI-env vars (different fallback chain).
Those keep wiring up the lower-level helpers by hand.

Net `-73 / +63` across 9 files; conceptually the bigger win is
that "the prelude of a Mergify command" is now a named concept
with one fix-it-once point.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Change-Id: I1b272570f6802dd13438c3d9baf26709b196574d
@jd jd force-pushed the devs/jd/worktree-rust-port/introduce-commandcontext-queue-freeze-prelude--1b272570 branch from d599400 to 5143191 Compare May 27, 2026 08:27
@jd jd temporarily deployed to func-tests-live May 27, 2026 08:27 — with GitHub Actions Inactive
@mergify mergify Bot deployed to Mergify Merge Protections May 27, 2026 08:28 Active
Base automatically changed from devs/jd/worktree-rust-port/share-test-scaffolding-via-mergify-test-support--f9d688cd to main May 27, 2026 13:50
@mergify mergify Bot requested a review from a team May 27, 2026 14:05
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 27, 2026

Merge Queue Status

This pull request spent 20 minutes 18 seconds in the queue, including 18 minutes 58 seconds running CI.

Required conditions to merge

mergify Bot added a commit that referenced this pull request May 27, 2026
@mergify mergify Bot added the queued label May 27, 2026
mergify Bot added a commit that referenced this pull request May 27, 2026
@mergify mergify Bot merged commit ed14b56 into main May 27, 2026
19 checks passed
@mergify mergify Bot deleted the devs/jd/worktree-rust-port/introduce-commandcontext-queue-freeze-prelude--1b272570 branch May 27, 2026 14:34
@mergify mergify Bot removed the queued label May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants